import Data from './data'
export default class Deal {
    constructor() {
        this.x = '';
    }
    ConvertPinyin(y) {
        this.x = y;
        var l2 = this.x.length;
        var I1 = '';
        var reg = new RegExp('[a-zA-Z0-9\- ]');
        for (var i = 0; i < l2; i++) {
            var val = this.x.substr(i, 1);
            var sName = this.arraySearch(val, Data);
            if (reg.test(val)) {
                I1 += val;
            } else if (sName !== false) {
                let ii = sName.substr(0, 1)
                I1 += ii;
            }
        }
        I1 = I1.replace(/ /g, '-');
        while (I1.indexOf('--') > 0) {
            I1 = I1.replace('--', '-');
        }
        return I1;
    }
    arraySearch(l1, l2) {
        for (var name in Data) {
            if (Data[name].indexOf(l1) != -1) {
                return this.ucfirst(name);
                break;
            }
        }
        return false;
    }
    ucfirst(l1) {
        if (l1.length > 0) {
            var first = l1.substr(0, 1).toUpperCase();
            var spare = l1.substr(1, l1.length);
            return first + spare;
            // return first;
        }
    }
}